
#set build, supported by cross compile 
CC = $(SUCROSS_C)g++
C = $(SUCROSS_C)gcc
AR = $(SUCROSS_C)ar
CFLAGS +=  $(patsubst %,-I%,$(subst :, ,$(VPATH)))
CPPFLAGS +=  $(patsubst %,-I%,$(subst :, ,$(VPATH)))

#file size larger 2GB
CFLAGS += -D_FILE_OFFSET_BITS=64
CPPFLAGS += -D_FILE_OFFSET_BITS=64

#project public files
COM = ../../public/
COMINC = $(COM)inc/
COMLIB = $(COM)lib/
ZLOG = ../../3rd-party/zlog/
ZLOGINC = $(ZLOG)inc/
ZLOGLIB = $(ZLOG)lib/

LIBS = -lpthread -lcurses -lz

#set env variable
VPATH = $(COMINC): $(COMLIB): $(ZLOGINC): $(ZLOGLIB)

#get all files, not include db
FILTER = $(COM)filename.cpp $(COM)stringex.cpp $(COM)crc.cpp
SOURCE = $(wildcard *.cpp)  $(filter $(FILTER), $(wildcard $(COM)*.cpp)) 
OBJS = $(patsubst %.cpp,%.o,$(SOURCE))

#user model name, pls replace by yourself
all : libs7comm.su libs7comm.a
libs7comm.su : $(OBJS)
	$(CC) -shared -fPIC -Wall $(CPPFLAGS) -o $@ $^

libs7comm.a : $(OBJS)
	$(AR) -rcs libs7comm.a $(OBJS)

.PHONY : clean
clean :
	-rm -f libs7comm.* $(patsubst %.o,%.d,$(OBJS)) $(OBJS)

include $(SOURCE:.cpp=.d)	
	
%.o:%.cpp
	$(CC) -Wall -O2 $(CPPFLAGS) -c $< -o $@

#get all dependencies
%.d:%.cpp
	@set -e; rm -f $@; \
	$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$